//JavaScript Doccument
var app = Common.initApp(['ngAnimate', 'ui.bootstrap', 'angular.filter']);
Common.initDirective(app);
app.controller('relevanceconfigListController', ['$scope', '$http', 'uiGridConstants', '$templateCache',
    function ($scope, $http, uiGridConstants, $templateCache) {
        $scope.relevanceconfig = {};
        $scope.relevanceconfigGrid = {
            dependence : {uiGridConstants : uiGridConstants, $templateCache : $templateCache},
            gridID : 'relevanceconfigGrid',
            height : function () {
                $(function () {
                    var gridHeight = ($('.edit-body').height() - 43-28-7) + "px";
                    angular.element($(".relevanceconfigGrid")).css('height', gridHeight);
                });
                $(window).resize(function () {
                    var gridHeight = ($('.edit-body').height() - 43-28-7) + "px";
                    angular.element($(".relevanceconfigGrid")).css('height', gridHeight);
                })
            },
            gridOptions : {
                enableVerticalScrollbar : uiGridConstants.scrollbars.NEVER,
                enableHorizontalScrollbar : uiGridConstants.scrollbars.NEVER,
                enableVerticalScrollbar : false, //默认grid滚动条不显示，如果将false改为true就可显示滚动条
                enableHorizontalScrollbar :false,
				enableSelectAll : false,         //是否全选选择框按钮
				enableRowHeaderSelection : false, //是否选择框按钮
                columnDefs : [
                    {name : 'ROW_ID', displayName : '序号', width : '40', cellClass : 'grid-col-center',enableSorting:false},
					{ name : 'XH',enableSorting:false,displayName : ' 配置编号', cellClass : 'grid-col-left'},
					{ name : 'YWMC',enableSorting:false,displayName : '业务类型名称', cellClass : 'grid-col-left'},
					{ name : 'YWLXDM',enableSorting:false,displayName : '业务类型代码', cellClass : 'grid-col-left'},
					{ name : 'GLLBSQL',enableSorting:false,displayName : '关联列表SQL', cellClass : 'grid-col-left'},
                    {name : 'OPERATE', displayName : '操作',  width : '120',cellClass : 'grid-col-center',enableSorting:false,
                        cellTemplate : '<a class="grid-vertical-middle" href="javascript:void(0);" ng-click="grid.appScope.relevanceconfigGrid.gridEvent.openEdit(grid, row);">编辑</a>  ' +
                        '<a class="grid-vertical-middle" href="javascript:void(0);" ng-click="grid.appScope.relevanceconfigGrid.gridEvent.openDetail(grid, row);">详情</a>  '
					}
				]
			},
			dataConfig : {
				url: Common.webRoot() + '/business/relevance/config/relevanceconfigcontroller/queryRelevanceConfigs',
				data : $scope.searchData,
				appendSuccess: function (response) {

				}
			},
			gridEvent : {
				_rowClick : function (row, $event) {
					Common.grid.rowClickStyle($event);

				},
				_pageChanged : function () {
					Common.page.pageChanged($scope, $http, $scope.relevanceconfigGrid);
				},
				_refresh : function () {
					//按需要修改的查询条件
					$scope.relevanceconfigGrid.dataConfig.data.MC = $scope.filterValue;
					Common.page.send($scope, $http, $scope.relevanceconfigGrid);
				},
				_changeItemsPerPage : function (item) {
					$scope.relevanceconfigGrid.dataConfig.data.pageSize = item;
					Common.page.send($scope, $http, $scope.relevanceconfigGrid);
				},
				_sortChange : function () {
					$scope.relevanceconfigGrid.dataConfig.data.MC = $scope.filterValue;
					Common.page.send($scope, $http, $scope.relevanceconfigGrid);
				},
				//以下是Grid使用到的自定义函数
				openEdit: function (grid, row) {
					//添加你需要的逻辑，默认提供弹出层打开编辑页面
					Common.dialog({
						url: Common.webRoot() + '/business/relevance/config/relevanceconfigcontroller/edit/' + row.entity.XH,
						title: '编辑',
						type: 'open',
						width: '75%',
						height: '75%',
						skin:'skin-default-class',
						end: function(){
							$scope.queryRelevanceConfig();
						}
					});
				},
				openDetail: function(grid, row){
					Common.dialog({
						url: Common.webRoot() + '/business/relevance/config/relevanceconfigcontroller/detail/'  + row.entity.XH,
						title: '详情(只读)',
						type: 'open',
						width: '75%',
						height: '75%',
						skin:'skin-default-class'
					});
				},
			}
		};
        Common.grid.initConfig($scope, $http, $scope.relevanceconfigGrid);

        //按下Enter键触发的函数
        Common.onKeyPress(function () {
            //添加你需要的逻辑
            $scope.queryRelevanceConfig();
        });

        //查询按钮绑定的函数
        $scope.queryRelevanceConfig = function () {
            Common.page.pageChanged($scope, $http, $scope.relevanceconfigGrid);
        };
		
		//清空查询条件
		$scope.clearData = function(){
			for(var key in $scope.searchData){
                $scope.searchData[key] = '';
            }
			$scope.queryRelevanceConfig();
		};

        $scope.deleteRelevanceConfig = function () {
            var selectedModel = $scope.relevanceconfigGrid.gridApi.selection.getSelectedRows();
            if(selectedModel == null || selectedModel.length < 1) {
                Common.dialog({
                    type : 'alert',
                    content : '请选中要删除的数据'
                });
                return;
            }
            var deleteConfig = {
                url : Common.webRoot() + '/business/relevance/config/relevanceconfigcontroller/deleteRelevanceConfig',
                method : 'POST',
                showTips : true,
                data: JSON.stringify({'models': selectedModel}),
                success : function (repsonse) {
                    //添加你需要的逻辑
                    $scope.queryRelevanceConfig();
                },
                error : function (response) {
                    throw new Error('请求[' + deleteConfig.url + ']出错,[' + response.data + ']');
                }
            };
            	Common.dialog({
        		type : "confirm",
        		content : "您确定要删除选中的数据吗？",
        		callback : function() {
        			Common.send($scope, $http, deleteConfig);
        		}});
        };

        $scope.addRelevanceConfig = function () {
            Common.dialog({
                url: Common.webRoot() + '/business/relevance/config/relevanceconfigcontroller/add',
                title: '新增',
                type: 'open',
                width: '75%',
                height: '75%',
                skin:'skin-default-class',
                end: function(){
                    $scope.queryRelevanceConfig();
                }
            });
        }
        //显示隐藏切换
	$scope.showorhide = function(){
		$('#showorhide-up').toggle('500');
		$('#showorhide-down').toggle('500');
		$('.query-body').toggle('500');
	}
    }]).filter('mapInfo', function() {
    return function(input){
        return input == '' ? 'AAA' : 'BBB';
    }
});